#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

typedef long long ll;
typedef double db;
typedef vector < int > vec;
typedef pair < int , int > pii;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 2e5 + 10;

int c[11], a[11][N], n, m;
vec al[N];

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
	n = in; rep(i, 0, n - 1) { c[i] = in; rep(j, 0, c[i] - 1) a[i][j] = in; }
	m = in; rep(i, 1, m) rep(j, 1, n) al[i].pb(in - 1);
	sort(al + 1, al + m + 1);
	vec cur; rep(i, 0, n - 1) cur.pb(c[i] - 1);
	if(!binary_search(al + 1, al + m + 1, cur)) {
		for(auto x : cur) printf("%d ", x + 1); return 0;
	}
	vec ans; ll tans = 0;
	rep(i, 1, m) {
		ll s = 0; rep(j, 0, n - 1) s += a[j][al[i][j]];
		vec d = al[i];
		rep(j, 0, n - 1)
			if(d[j]) {
				s -= a[j][d[j]]; d[j]--;
				s += a[j][d[j]]; if(!binary_search(al + 1, al + m + 1, d) && s > tans) tans = s, ans = d;
				s -= a[j][d[j]]; d[j]++;
				s += a[j][d[j]];
			}
	}
	for(auto x : ans) printf("%d ", x + 1); return 0;
}
